package com.example.javamaday.leetcode;

import com.example.javamaday.leetcode.base.TreeNode;

import java.util.HashMap;
import java.util.Stack;

public class LeetCodeTest0965 {

    public static void main(String[] args) {

    }

    public boolean isUnivalTree(TreeNode root) {
        HashMap<Integer, Integer> valueMap = new HashMap<>();
        Stack<TreeNode> treeNodeStack = new Stack<>();
        treeNodeStack.push(root);
        while (!treeNodeStack.isEmpty()) {
            TreeNode node = treeNodeStack.pop();
            valueMap.put(node.val, node.val);
            if (node.right != null) {
                treeNodeStack.push(node.right);
            }
            if (node.left != null) {
                treeNodeStack.push(node.left);
            }
        }
        return valueMap.size() == 1;
    }

}
